# -*- coding:utf-8 -*-
# author:hp
# datetime:18-6-21 下午4:38
# software: PyCharm

import numpy as np


class Process:
    def __init__(self, name, maxNeed, allocation):
        self.name = name
        self.maxNeed = maxNeed
        self.allocation = allocation
        self.need = self.maxNeed - self.allocation

    def alloc(self, resourse):
        # resource是可用资源数，分配完后  已分配=全分配 所需为0
        resourse += self.allocation
        self.allocation = self.maxNeed
        self.need = 0
        return resourse

    def __repr__(self):
        return "进程：{}  MaxNeed：{}  allocation：{}  need：{}".format(self.name, self.maxNeed, self.allocation, self.need)

# A = Process('A', np.array([5, 6, 4]), np.array([2, 3, 1]))
# resource = np.array([5, 4, 5])
# print(A)
# print(">", False in (resource > A.need))
# resource = A.alloc(resource)
# print("resource", resource)
# print(A)
